package LeetCode.leetcode225;

import java.util.LinkedList;
import java.util.Queue;

public class Review1 {
    private Queue<Integer> queue1;
    private Queue<Integer> queue2;
    public Review1() {
        queue1 = new LinkedList<>();
        queue2 = new LinkedList<>();
    }

    public void push(int x) {
        queue1.offer(x);
    }

    public int pop() {
        int res = 0;
        while (!queue1.isEmpty()){
            int tmp = queue1.poll();
            if (queue1.isEmpty()){
                res = tmp;
            }else {
                queue2.offer(tmp);
            }
        }
        while (!queue2.isEmpty()){
            queue1.offer(queue2.poll());
        }
        return res;
    }

    public int top() {
        int res = 0;
        while (!queue1.isEmpty()){
            int tmp = queue1.poll();
            if (queue1.isEmpty()){
                res = tmp;
            }
            queue2.offer(tmp);
        }
        while (!queue2.isEmpty()){
            queue1.offer(queue2.poll());
        }
        return res;
    }

    public boolean empty() {
        return queue1.isEmpty();
    }
}
